package movieGandalf.dataObjects;

import java.sql.Connection;

import movieGandalf.database.MovieTools;
import movieGandalf.logicGuiConnection.Language;

public class LanguageImp implements Language{
	
	private Integer id;
	
	private String language;
	
	public LanguageImp(Integer id, String language){
		this.id = id;
		this.language = language;
	}
	
	public Integer getID() {
		return this.id;
	}

	public String getLanguage() {
		if (language != null)
			return language;
		
		if (id == null)
			return null;
		
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		language = MovieTools.getLanguage(conn, this.id);
		
		return language;
	}

	public void setID(Integer newID) {
		this.id = newID;
		
	}
	
	public void setLanguage(String newLanguage) {
		this.language = newLanguage;
	}

	public boolean update() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.updateLanguage(conn, this);
	}
	
	public boolean delete() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteObject(conn,this);
	}
}
